'use strict';

const api = require('../../config/api');
const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    // 获取新闻
    const res = await ctx.curl(`${api.basicUrl}/Index/getIndex`, {
      // 必须指定 method
      method: 'GET',
      // 通过 contentType 告诉 HttpClient 以 JSON 格式发送
      contentType: 'json',
      // 明确告诉 HttpClient 以 JSON 格式处理返回的响应 body
      dataType: 'json',
    });

    // ctx.status = result.status;
    // ctx.set(result.headers);
    // ctx.body = ;
    await ctx.render('home.html', {
      pics: res.data.indexPics || [],
      news: res.data.indexNews || [],
      events: res.data.indexEvents || [],
      researchs: res.data.indexResearchs || [],
      mottos: res.data.indexMottos || [],
    });
  }
}

module.exports = HomeController;
